package guichatapplication;

import chatclient.ChatClient;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class GUIChatApplication {

    public static void main(String[] args) throws InterruptedException {
        try {
            //ChatClient network = ChatClient.getInstance();
            
            
            
            //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); // No additional Jar
            //UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");// Cool
            //UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
            
            //UIManager.setLookAndFeel("com.jtattoo.plaf.texture.TextureLookAndFeel");
            //UIManager.setLookAndFeel("");
            //UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel");
            
            UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel"); // Very cool
            //UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel"); // Cool
            //UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel"); // good
            //UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel"); //
            //UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel"); // good
            //UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
            
            do {
                String ipAddress = JOptionPane.showInputDialog(null, "Input server address", "Connect to server", JOptionPane.QUESTION_MESSAGE);
                if (ipAddress == null) {
                    break;
                }
                
                ChatClient.ServerAddress = ipAddress;

                ChatClient network = ChatClient.getInstance();
                if (ChatClient.isConnected()) {
                    MainWindow main = new MainWindow();
                    main.setVisible(true);

                    network.setOnLoginListener(main);
                    network.setOnRegistryListener(main);
                    network.setOnTransferListener(main);
                    network.setOnGroupListener(main);

                    network.run();
                    break;
                } else {
                    ChatClient.dispose();
                }
            } while (true);
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GUIChatApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(GUIChatApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(GUIChatApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(GUIChatApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
